<?php
class ViewOnceUrlGen_Service_Url 
{
	public function expireUrl($token)
	{
		$result = null;
		$uniqueToken = null;
		
		$uniqueTokensDbTable = new Application_Model_DbTable_UniqueTokens();
		try {
			$uniqueToken = $uniqueTokensDbTable->getUniqueTokenByToken($token);
		} catch (Exception $exception) {
			return array('code' => 'INVALID_TOKEN', 'status' => 'failed');
		}
		if ($uniqueToken['is_active'] === 'N') {
			return array('code' => 'URL_EXPIRED', 'status' => 'failed');
		} else {
			$uniqueToken['is_active'] = 'N';
			$uniqueTokensDbTable->update($uniqueToken, 'id = ' . (int) $uniqueToken['id']);
			
			return array('code' => 'OK', 'status' => 'success');
		}
	}
}